package com.netnovelstore.pojo;

import com.alibaba.fastjson2.JSON;
import com.netnovelstore.pojo.Enum.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Result<T> implements Serializable {
    private T objects;

    private String message;

    private Integer code;


    public static Result ok() {
        return new Result(null, ResultEnum.SUCCESS.getDesc(), ResultEnum.SUCCESS.getCode());
    }

    public static Result ok(Object objects) {
        return new Result(objects,ResultEnum.SUCCESS.getDesc(), ResultEnum.SUCCESS.getCode());
    }


    public static Result ok(Object objects, String message) {
        return new Result(objects,message,ResultEnum.SUCCESS.getCode());
    }

    public static Result defeat(){
        return new Result(null,ResultEnum.DEFEAT.getDesc(), ResultEnum.DEFEAT.getCode());
    }

    public static Result defeat(Object objects) {
        return new Result(objects,ResultEnum.DEFEAT.getDesc(), ResultEnum.DEFEAT.getCode());
    }


    public static Result defeat(Object objects, String message) {
        return new Result(objects,message,ResultEnum.DEFEAT.getCode());
    }

    public static Result defeat(String message) {
        return new Result(null,message,ResultEnum.DEFEAT.getCode());
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
